package com.quktzhuanka.app.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.quktzhuanka.app.config.Constants;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.common.SPUtils;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pay_result);

		api = WXAPIFactory.createWXAPI(this, Constants.WX_APP_ID);
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
//		Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);
		String paymentSn = SPUtils.getStringData(WXPayEntryActivity.this,
				"weiXinPaymentSn", "");//流水号
//		Toast.makeText(WXPayEntryActivity.this,"支付是否成功--->"+ resp.errCode+"   orderSn="+orderSn, 5).show();
//		Toast.makeText(WXPayEntryActivity.this,"支付是否成功--->"+ resp.errCode+"   paymentSn="+paymentSn, 5).show();
		Toast.makeText(WXPayEntryActivity.this,"支付成功1111！", Toast.LENGTH_LONG).show();
		Toast.makeText(WXPayEntryActivity.this,"支付成功2222！", Toast.LENGTH_LONG).show();
		Toast.makeText(WXPayEntryActivity.this,"支付成功3333！", Toast.LENGTH_LONG).show();
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

			switch (resp.errCode) {
			case 0:
				Toast.makeText(WXPayEntryActivity.this,"支付成功！", Toast.LENGTH_LONG).show();
				this.finish();
				break;
			case -2:
				Toast.makeText(WXPayEntryActivity.this,"用户取消！", Toast.LENGTH_LONG).show();
				this.finish();
				break;
			case -1:
				Toast.makeText(WXPayEntryActivity.this,"请求失败，请重新下单！", Toast.LENGTH_LONG).show();
				this.finish();
				break;
			}
		}
	}
	

}